import { EntitySchema, Ref } from '@mikro-orm/core';
import { Users } from './Users';

export class WechatAppid {
  id!: string;
  appid!: string;
  wxid?: string;
  uuid!: string;
  uin?: number;
  expiredTime?: string;
  headImgUrl?: string;
  status?: number;
  nickName?: string;
  mobile?: string;
  alias?: string;
  owner?: Ref<Users>;
}

export const WechatAppidSchema = new EntitySchema({
  class: WechatAppid,
  properties: {
    id: { primary: true, type: 'string', columnType: 'bigint' },
    appid: { type: 'string', length: 255 },
    wxid: { type: 'string', length: 255, nullable: true },
    uuid: { type: 'string', length: 255 },
    uin: { type: 'number', nullable: true },
    expiredTime: { type: 'string', length: 255, nullable: true },
    headImgUrl: { type: 'string', length: 1000, nullable: true },
    status: { type: 'number', columnType: 'tinyint', nullable: true },
    nickName: { type: 'string', length: 255, nullable: true },
    mobile: { type: 'string', length: 255, nullable: true },
    alias: { type: 'string', length: 255, nullable: true },
    owner: {
      reference: 'm:1',
      entity: () => Users,
      ref: true,
      nullable: true,
      index: 'owner_app',
    },
  },
});
